<?php
namespace App\Service\Sms;

use App\Facade\Http;

class SmsService
{
    // 配置
    public $config = [];
    
    public function __construct($config)
    {
        $this->config = $config;
    }
    
    // http
    protected function http()
    {
        return Http::create([
            'base_uri' => $this->config['api'],
        ]);
    }
    
    // 发送短信
    public function send($phone, $content)
    {
        $response = $this->http()->get('', [
            'query' => array_merge($this->config, [
                'm' => $phone,
                'c' => $content
            ])
        ]);
        
        $response = (string) $response->getBody();
        return $response == '0';
    }
}